package cn.quang.search.admin.utils;

import cn.quang.search.admin.exceptions.WrongArgumentException;
import io.micrometer.common.util.StringUtils;

import java.util.Collection;

public class AssertUtils {
    public static void argumentNull(Object argument, String message) {
        if(argument == null)
            throw new WrongArgumentException(message);
    }

    public static void argumentNotNull(Object argument, String message) {
        if(argument != null)
            throw new WrongArgumentException(message);
    }

    public static void argumentBlank(String argument, String message) {
        if(StringUtils.isBlank(argument))
            throw new WrongArgumentException(message);
    }

    public static void argumentNegative(Number argument, String message) {
        if(argument == null || argument.longValue() < 0)
            throw new WrongArgumentException(message);
    }

    public static void argumentNegativeOrZero(Number argument, String message) {
        if(argument == null || argument.longValue() <= 0)
            throw new WrongArgumentException(message);
    }

    public static void argumentPositive(Number argument, String message) {
        if(argument != null && argument.longValue() > 0)
            throw new WrongArgumentException(message);
    }

    public static void argumentPositiveOrZero(Number argument, String message) {
        if(argument != null && argument.longValue() >= 0)
            throw new WrongArgumentException(message);
    }

    public static void argumentNotEquals(Object argument, Object other, String message) {
        if((argument == null && other != null) || (argument != null && !argument.equals(other)))
            throw new WrongArgumentException(message);
    }

    public static void argumentEquals(Object argument, Object other, String message) {
        if((argument == null && other == null) || (argument != null && argument.equals(other)))
            throw new WrongArgumentException(message);
    }

    public static void argumentTrue(boolean argument, String message) {
        if(argument)
            throw new WrongArgumentException(message);
    }

    public static void argumentFalse(boolean argument, String message) {
        if(!argument)
            throw new WrongArgumentException(message);
    }

    public static void argumentCollectionEmpty(Collection<?> collection, String message) {
        if(collection == null || collection.isEmpty())
            throw new WrongArgumentException(message);
    }

    public static void argumentCollectionNotEmpty(Collection<?> collection, String message) {
        if(collection != null && !collection.isEmpty())
            throw new WrongArgumentException(message);
    }
}
